package entities;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import beans.ItemCartaBean;

@Entity
@Table (name= "itemsCartas")
public class ItemCartaEntity implements Serializable{

	@Transient
	private static final long serialVersionUID = 1L;
	
	@Id @GeneratedValue
	private Integer id;
	private float precio;
	private float comision;
	@ManyToOne
	@JoinColumn (name="idPlato")
	private PlatoEntity plato;
	
	
	public ItemCartaEntity() {
		//plato = new PlatoEntity();
	}

	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public float getPrecio() {
		return precio;
	}
	public void setPrecio(float precio) {
		this.precio = precio;
	}
	public float getComision() {
		return comision;
	}
	public void setComision(float comision) {
		this.comision = comision;
	}
	public PlatoEntity getPlato() {
		return plato;
	}
	public void setPlato(PlatoEntity plato) {
		this.plato = plato;
	}
	
	public ItemCartaBean getItemCartaBean(){
		ItemCartaBean icb = new ItemCartaBean();
		icb.setId(id);
		icb.setPlato(plato.getPlatoBean());
		icb.setPrecio(precio);
		return icb;
	}


	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + Float.floatToIntBits(comision);
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((plato == null) ? 0 : plato.hashCode());
		result = prime * result + Float.floatToIntBits(precio);
		return result;
	}


	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ItemCartaEntity other = (ItemCartaEntity) obj;
		if (Float.floatToIntBits(comision) != Float
				.floatToIntBits(other.comision))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (plato == null) {
			if (other.plato != null)
				return false;
		} else if (!plato.equals(other.plato))
			return false;
		if (Float.floatToIntBits(precio) != Float.floatToIntBits(other.precio))
			return false;
		return true;
	}

	
}

